package com.ksl.kinglockguard.utils;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.os.Handler;

import com.lsk.open.core.MyLog;

public class TaskStackUtil {
	static Map<String,String>  activityMap = new HashMap<String,String>();
	private static final String PROCESS_NAME =":kswebview";
	private static  String proce_name ="";
	static Handler handler = new Handler();
	public static void pullStack(String activity){
		if(activityMap.containsKey(activity)){
			activityMap.remove(activity);
		}
	}
	public static void pushStack(String activity){
		if(!activityMap.containsKey(activity)){
			activityMap.put(activity,"");
			MyLog.i("wmm", "activityMap : size "+ activityMap.size());
		}
	}
	
	public static void startKillThread(Context context){
		if(activityMap.size()<=0){
			if(proce_name.equals("")){
				proce_name=context.getPackageName()+PROCESS_NAME;
			}
			handler.removeCallbacks(killThread);
			handler.postDelayed(killThread, 35000);
		}
	}
	
	public static boolean isFirstActivityStart(){
		if(activityMap.size()==1){
			return true;
		}
		else return false;
	}
	

	static Runnable killThread = new Runnable() {
		
		@Override
		public void run() {
			try {
				Thread.sleep(2*1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			MyLog.i("wmm", "activityMap  :  "+activityMap.toString());
			if(activityMap.size()<=0){
				MyLog.e("ydy","******TaskStack**** killprocess**");
				KingsSystemUtils.stopMyProcess(proce_name);
			}
		}
	};
}
